using System;
using System.Security.Cryptography;
using System.Text;

namespace Sunny.UI;

public static class RSANative
{
	public static string RSAEncrypt(string content, string xmlPublicKey)
	{
		using RSACryptoServiceProvider rSACryptoServiceProvider = new RSACryptoServiceProvider();
		rSACryptoServiceProvider.FromXmlString(xmlPublicKey);
		return Convert.ToBase64String(rSACryptoServiceProvider.Encrypt(Encoding.Default.GetBytes(content), fOAEP: false));
	}

	public static string RSADecrypt(string content, string xmlPrivateKey)
	{
		using RSACryptoServiceProvider rSACryptoServiceProvider = new RSACryptoServiceProvider();
		rSACryptoServiceProvider.FromXmlString(xmlPrivateKey);
		byte[] bytes = rSACryptoServiceProvider.Decrypt(Convert.FromBase64String(content), fOAEP: false);
		return Encoding.Default.GetString(bytes);
	}
}
